package com.jadeen.controller.serverController;

import cn.dev33.satoken.stp.StpUtil;
import com.jadeen.common.controller.BaseController;
import com.jadeen.common.domain.AjaxResult;
import com.jadeen.entity.domain.Category;
import com.jadeen.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资源分类Controller
 * 
 * @author jadeen
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/share/category")
public class CategoryController extends BaseController
{
    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询资源分类列表
     */
    @GetMapping("/list")
    public AjaxResult list(Category category)
    {
        System.out.println("当前会话是否登录：" + StpUtil.isLogin());
        List<Category> list = categoryService.selectCategoryList(category);
        return success(list);
    }


    /**
     * 获取资源分类详细信息
     */
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(categoryService.selectCategoryByCategoryId(categoryId));
    }

    /**
     * 新增资源分类
     */
    @PostMapping
    public AjaxResult add(@RequestBody Category category)
    {
        return toAjax(categoryService.insertCategory(category));
    }

    /**
     * 修改资源分类
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Category category)
    {
        return toAjax(categoryService.updateCategory(category));
    }

    /**
     * 删除资源分类
     */
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(categoryService.deleteCategoryByCategoryIds(categoryIds));
    }
}
